
*This file creates the local level balance test table 5.

cd "$temp"


*Input shift share exposure measures linked with controls
use "$temp\municipality_shares_bartik_1939", clear


******************************************
*Balance Table 5
******************************************

global municontrols agrishare_1940 manushare_1940


preserve 

*Generate local balance and file that can be removed from the remote server 

keep bartik_standardized2  ln_pop_1940 agrishare_1940 manushare_1940 share_service_1940 share_construction_1940  swedish_share_1940 average_incometax_38 income_tax_payers38 ln_arable_1940 relative_cows1940 relative_tractors1940   ln_area lat lon  changepop changeagri changemanu change_service  change_construction  change_swe change_av_tax change_tax_payers chage_arable  changecows changetractors  city town laani50  ln_workersmean ln_factorynumber ln_salary change_ln_worker change_ln_factorynumber change_ln_salary code

save "$path\shift_share_balance_full", replace


eststo summstats: estpost sum    ln_pop_1940 share_service_1940 share_construction_1940 swedish_share_1940 average_incometax_38 income_tax_payers38   ln_arable_1940 relative_cows1940 relative_tractors1940  ln_workersmean ln_factorynumber  ln_salary manushare_1940 agrishare_1940 ln_area lat  lon 
esttab summstats using "$temp\tables\sumstats.tex", replace cell("mean sd")   



foreach x in ln_pop_1940 share_service_1940 share_construction_1940 swedish_share_1940 average_incometax_38 income_tax_payers38   ln_arable_1940 relative_cows1940 relative_tractors1940  ln_workersmean ln_factorynumber ln_salary   manushare_1940  agrishare_1940 ln_area lat  lon {
reg `x' bartik_standardized2  $municontrols   city town i.laani50 , r
estimates store b`x'  
}


esttab b* using "$temp\tables\TABLE_balance_b.tex", replace b(%9.3f) se(%9.3f) keep(bartik_standardized2)  star(* .1 ** .05 *** .01)
esttab b* using "$temp\tables\TABLE_balance_b.xls", replace b(%9.3f) se(%9.3f) keep(bartik_standardized2)  star(* .1 ** .05 *** .01)


est clear


foreach x in   changepop change_service change_construction   change_swe change_av_tax change_tax_payers chage_arable changecows changetractors   change_ln_worker change_ln_factorynumber change_ln_salary  changeagri changemanu {
reg `x' bartik_standardized2   $municontrols       city town  i.laani50, r
estimates store b`x'  
}


esttab b* using "$temp\tables\TABLE_balancetrend_b.tex", replace b(%9.3f) se(%9.3f) keep(bartik_standardized2)  star(* .1 ** .05 *** .01)
esttab b* using "$temp\tables\TABLE_balancetrend_b.xls", replace b(%9.3f) se(%9.3f) keep(bartik_standardized2)  star(* .1 ** .05 *** .01)


restore 


******************************************
****Run the same for large industry groups (Robustness)
*******************************************



foreach y in 27 36 37 38 {
est clear

local industry share_ind`y'

foreach x in  ln_pop_1940 share_service_1940 share_construction_1940 swedish_share_1940 average_incometax_38 income_tax_payers38   ln_arable_1940 relative_cows1940 relative_tractors1940  ln_workersmean ln_factorynumber ln_salary   manushare_1940  agrishare_1940 ln_area lat  lon {
reg `x' `industry'    $municontrols   city town i.laani50 , r
estimates store c`x'  
}



foreach x in    changepop change_service change_construction   change_swe change_av_tax change_tax_payers chage_arable changecows changetractors   change_ln_worker change_ln_factorynumber change_ln_salary  changeagri changemanu {
reg `x' `industry'   $municontrols       city town  i.laani50 , r
estimates store d`x'  
}


esttab c* using "$temp\tables\TABLE_balance_`industry'.tex", replace b(%9.3f) se(%9.3f) keep(`industry')  star(* .1 ** .05 *** .01)
esttab c* using "$temp\tables\TABLE_balance_`industry'.xls", replace b(%9.3f) se(%9.3f) keep(`industry')  star(* .1 ** .05 *** .01)

esttab d* using "$temp\tables\TABLE_balancetrend_`industry'.tex", replace b(%9.3f) se(%9.3f) keep(`industry')  star(* .1 ** .05 *** .01)
esttab d* using "$temp\tables\TABLE_balancetrend_`industry'.xls", replace b(%9.3f) se(%9.3f) keep(`industry')  star(* .1 ** .05 *** .01)
est clear
 }




//////
*Elastic net
///////


set seed 2511
elasticnet linear bartik_standardized2  ln_pop_1940 agrishare_1940 manushare_1940 share_service_1940 share_construction_1940  displaced_share_1940 swedish_share_1940 average_incometax_38 income_tax_payers38 ln_arable_1940 relative_cows1940 relative_tractors1940   ln_area lat lon  changepop changeagri changemanu change_service  change_construction  change_swe change_av_tax change_tax_payers chage_arable  railway changecows changetractors 


lassocoef
 
global enet  agrishare_1940  manushare_1940 income_tax_payers38   
